#include "FPSCounter.h"

FPSCounter::FPSCounter()
{
	_mClock = new Clock;
	_mFrameCount = 0;
	_mFPS= 0;
}
FPSCounter::~FPSCounter()
{
	if(_mClock != NULL)
	{
		delete _mClock;
		_mClock = NULL;
	}
	if(_mDisplayText != NULL)
	{
		delete _mDisplayText;
		_mDisplayText = NULL;
	}
}

void FPSCounter::Render(RenderWindow *window)
{
	char buffer[16];
	sprintf(buffer, "FPS: %i%", FPS());

	_mDisplayText->setString(buffer);
	window->draw(*_mDisplayText);
}
void FPSCounter::Update()
{	
	if(_mClock->getElapsedTime() >= sf::seconds(1.f))
	{
		_mFPS = _mFrameCount;
		_mFrameCount = 0;
		_mClock->restart();
	}
	_mFrameCount++;
}
bool FPSCounter::Load(FontManager *FontLibrary)
{
	_mDisplayText = new Text("FPS: NaN", *(FontLibrary->GetFont("Arial18")), 18);
	_mDisplayText->setPosition(0,580);
	_mDisplayText->setColor(Color::Yellow);
	return true;
}

int FPSCounter::FPS()
{
	return _mFPS;
}